﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LPV_POS.mh_pos.mh_ban_hang
{
    public partial class mh_banhang8_Giam_TienGio : Form
    {
        public mh_banhang8_Giam_TienGio()
        {
            InitializeComponent();
        }

        private void mh_banhang8_Giam_TienGio_Load(object sender, EventArgs e)
        {
            this.LoadGiamGia();
        }
        void LoadGiamGia()
        {
            cpublic ocpublic = new cpublic();
            string d1 = ocpublic.Registry_Get("dtpGiamTienGio_Tu");
            string d2 = ocpublic.Registry_Get("dtpGiamTienGio_Den");
            string d3 = ocpublic.Registry_Get("nudGiam_TienGio_PhanTram");
            if (d1.Length == 8 && d2.Length == 8)
            {
                //tu ngay
                string l1 = d1.Substring(0, 4);
                string l2 = d1.Substring(4, 2);
                string l3 = d1.Substring(6, 2);
                dtpGiamTienGio_Tu.Value = new DateTime(int.Parse(l1), int.Parse(l2), int.Parse(l3), 0, 0, 0);

                //den ngay
                l1 = d2.Substring(0, 4);
                l2 = d2.Substring(4, 2);
                l3 = d2.Substring(6, 2);
                dtpGiamTienGio_Den.Value = new DateTime(int.Parse(l1), int.Parse(l2), int.Parse(l3), 23, 59, 59);

                decimal dc = 0;
                decimal.TryParse(d3, out dc);
                nudGiam_TienGio_PhanTram.Value = dc;
            }
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            ocpublic.Registry_Set("dtpGiamTienGio_Tu", dtpGiamTienGio_Tu.Value.ToString("yyyyMMdd"));
            ocpublic.Registry_Set("dtpGiamTienGio_Den", dtpGiamTienGio_Den.Value.ToString("yyyyMMdd"));
            ocpublic.Registry_Set("nudGiam_TienGio_PhanTram", nudGiam_TienGio_PhanTram.Value);

            MessageBox.Show("Lưu thành công");
        }
    }
}
